#include "stdafx.h"
#include "base_tex_bank.h"
#include "pageInfoGetter.hpp"
#include "ilttexinterface.h"
#include "..\clientinterfaces.h"

base_tex_bank& base_tex_bank::single()
{
	static base_tex_bank _single;
	return _single;

}

HTEXTURE base_tex_bank::get_tex( int _id )
{
	return m_texs_value[_id];


}

HTEXTURE base_tex_bank::get_tex( std::string name )
{
	int id=m_texs[name];
	return m_texs_value[id];

}

int base_tex_bank::get_tex_nums()
{
	return m_texs.size();

}

base_tex_bank* base_tex_bank::get_ptr()
{
	return this;
}

base_tex_bank::base_tex_bank():
m_page_name("textures")
{
	//Utility::page_info_getter::Instance().add_page(m_tex_file,m_page_name);
	
	m_size=Utility::page_info_getter::Instance().get(m_page_name,"info","size",m_size);
	for (int i=0;i<m_size;++i)
	{
		static int tempid;
		static std::string tempstr;
		char tempgroup[10];
		sprintf(tempgroup,"tex%d",i);
		tempid=Utility::page_info_getter::Instance().get(m_page_name,tempgroup,"id",tempid);
		tempstr=Utility::page_info_getter::Instance().get(m_page_name,tempgroup,"name",tempstr);
		m_texs.insert(std::make_pair(tempstr,tempid));
		LTRESULT result=0;
		result=g_pLTCTexInterface->CreateTextureFromName(temphtex,("UIconfigs/textures/"+tempstr+".dtx").c_str());

		m_texs_value.insert(std::make_pair(tempid,temphtex));


	}

}
base_tex_bank::~base_tex_bank()
{
	for (m_texs_value_it=m_texs_value.begin();m_texs_value_it!=m_texs_value.end();++m_texs_value_it	)
	{
		g_pLTCTexInterface->ReleaseTextureHandle((*m_texs_value_it).second);
	}
	m_texs.clear();

}